package cn.itcast.com.network.tcp.exer;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //创建socket对象,这个指定的端口号ip都是本身的
        ServerSocket serversocket = new ServerSocket(8282);
        //使用accept，接受请求，并建立连接
        //阻塞
        Socket socket = serversocket.accept();
        //正式开始数据传输
        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        String s = "接收到了来自"+socket.getInetAddress()+":"+socket.getPort()+
                " 发送的消息";
        outputStream.write(s.getBytes());
    }
}
